using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 游戏对象服务，负责收发游戏对象（对象）
/// </summary>
public class GameObjectService : BaseManager<GameObjectService>
{
    // BaseObject baseObject;

    // //对象池类型（正在使用，未使用）（角色，子弹，场景物体等）
    // //对象池中的方法（保存，取出，加载等）
    // //泛型对象池类型

    // Dictionary<E_Object_Type, Dictionary<int, List<BaseObject>>> UnUsePoolDic = new Dictionary<E_Object_Type, Dictionary<int, List<BaseObject>>>();
    // public Dictionary<E_Object_Type, Dictionary<int, List<BaseObject>>> UsePoolDic = new Dictionary<E_Object_Type, Dictionary<int, List<BaseObject>>>();

    // GameObject ScenesGameObject = new GameObject(nameof(ScenesGameObject));
    // GameObject UseObject = new GameObject(nameof(UseObject));
    // GameObject UnUseObject = new GameObject(nameof(UnUseObject));

    // /// <summary>
    // /// 实现接口，InitService，初始化服务
    // /// </summary>
    // public GameObjectService()
    // {
    //     UseObject.transform.SetParent(ScenesGameObject.transform);
    //     UnUseObject.transform.SetParent(ScenesGameObject.transform);
    //     baseObject = new BaseObject();
    // }
    // //保存对象至对象池
    // public void SaveObjToPool<T>(E_Object_Type type, int objId, T t) where T : BaseObject, new()
    // {

    //     t.GameObject.transform.SetParent(UnUseObject.transform);
    //     GetList<T>(UsePoolDic, type, objId).Remove(t);
    //     GetList<T>(UnUsePoolDic, type, objId).Add(t);
    //     Debug.Log($"存入时长度{GetList<T>(UnUsePoolDic, type, objId).Count}");
    // }
    // //从对象池中得到对象
    // public T GetObjFromPool<T>(E_Object_Type type, int objId) where T : BaseObject, new()
    // {
    //     Debug.Log($"取出时长度{GetList<T>(UnUsePoolDic, type, objId).Count}");
    //     if (GetList<T>(UnUsePoolDic, type, objId).Count > 0)
    //     {
    //         baseObject = GetList<T>(UnUsePoolDic, type, objId)[0];
    //         baseObject.GameObject.transform.SetParent(UseObject.transform);
    //         GetList<T>(UsePoolDic, type, objId).Add(baseObject);
    //         GetList<T>(UnUsePoolDic, type, objId).RemoveAt(0);
    //         return baseObject as T;
    //     }
    //     else
    //     {
    //         T t = new T();
    //         t = GetObjectReady(E_CreatObject_State.realTime, type, objId, t);
    //         GetList<T>(UsePoolDic, type, objId).Add(t);
    //         t.GameObject.transform.SetParent(UseObject.transform);
    //         return t;
    //     }
    // }

    // List<BaseObject> GetList<T>(Dictionary<E_Object_Type, Dictionary<int, List<BaseObject>>> allDic, E_Object_Type type, int objId) where T : BaseObject, new()
    // {
    //     if (allDic.TryGetValue(type, out Dictionary<int, List<BaseObject>> dic))
    //     {
    //         if (dic.TryGetValue(objId, out List<BaseObject> list))
    //         {
    //             return list;
    //         }
    //         else
    //         {
    //             List<BaseObject> newList = new List<BaseObject>();
    //             dic.Add(objId, newList);
    //             return newList;
    //         }
    //     }
    //     else
    //     {
    //         List<BaseObject> newList = new List<BaseObject>();
    //         Dictionary<int, List<BaseObject>> newDic = new Dictionary<int, List<BaseObject>>();
    //         newDic.Add(objId, newList);
    //         allDic.Add(type, newDic);
    //         return newList;
    //     }
    // }
    // /// <summary>
    // /// 从对象池，或新建对象时的属性设置
    // /// </summary>
    // public T GetObjectReady<T>(E_CreatObject_State state, E_Object_Type type, int objId, T t) where T : BaseObject, new()
    // {

    //     switch (state)
    //     {
    //         case E_CreatObject_State.gameInit:  //先存后用
    //             t.InitBehaviour(objId);
    //             t.GameObject.transform.SetParent(UnUseObject.transform);
    //             t.GameObject.transform.position = Vector3.zero;
    //             t.GameObject.transform.rotation = new Quaternion(0, 0, 0, 0);
    //             return t;
    //         case E_CreatObject_State.realTime: //先用后存
    //             if (t.GameObject == null)
    //             {
    //                 t.InitBehaviour(objId);
    //             }
    //             t.GameObject.transform.SetParent(UseObject.transform);
    //             t.GameObject.transform.position = Vector3.zero;
    //             t.GameObject.transform.rotation = new Quaternion(0, 0, 0, 0);
    //             return t;
    //         default:
    //             Debug.LogWarning($"创建的对象为{null}");
    //             return null;
    //     }

    // }
}